package com.im.server.enterprise.business.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.im.server.enterprise.business.push.DepartmentPush;
import com.im.server.enterprise.common.bean.Department;
import com.im.server.enterprise.common.bean.DepartmentMember;
import com.im.server.enterprise.common.manager.DepartmentMemberManager;
import com.im.server.enterprise.common.service.DepartmentService;
import com.im.server.general.business.message.data.UserData;
import com.im.server.general.common.bean.UserHead;
import com.im.server.general.common.message.ResultMessage;
import com.im.server.general.common.service.UserService;
import com.im.server.general.common.service.api.UserBaseService;
import com.only.general.annotation.action.ActionMapping;
import com.only.general.annotation.action.MethodMapping;
import com.only.general.annotation.parameter.Define;
import com.only.net.session.SocketSession;

/**
 * 描述：
 * 
 * @author XiaHui
 * @date 2016年1月8日 下午8:12:59
 * @version 0.0.1
 */
@Component
@ActionMapping(value = "1.1100")
public class DepartmentAction {

	@Resource
	private UserService userService;
	@Resource
	private DepartmentService departmentSerivce;
	@Resource
	private DepartmentMemberManager departmentMemberManager;
	@Resource
	private DepartmentPush departmentPush;
	@Resource
	private UserBaseService userBaseService;

	@MethodMapping(value = "1.1.0001")
	public ResultMessage getUserList(SocketSession socketSession) {
		List<UserData> userDataList = departmentSerivce.getAllUserDataList();
		userService.setUserStatus(userDataList);
		ResultMessage message = new ResultMessage();
		message.put("userDataList", userDataList);
		return message;
	}

	@MethodMapping(value = "1.1.0002")
	public ResultMessage getDepartmentList(SocketSession socketSession) {
		List<Department> list = departmentSerivce.getAllDepartmentList();
		ResultMessage message = new ResultMessage();
		message.put("departmentList", list);
		return message;
	}

	@MethodMapping(value = "1.1.0003")
	public ResultMessage getDepartmentMemberList(SocketSession socketSession) {
		List<DepartmentMember> list = departmentSerivce.getAllDepartmentMemberList();
		ResultMessage message = new ResultMessage();
		message.put("departmentMemberList", list);
		return message;
	}

	@MethodMapping(value = "1.1.0004")
	public ResultMessage getDepartmentWithUserList() {
		List<UserData> userDataList = departmentSerivce.getAllUserDataList();
		userService.setUserStatus(userDataList);

		List<Department> departmentList = departmentSerivce.getAllDepartmentList();
		List<DepartmentMember> departmentMemberList = departmentSerivce.getAllDepartmentMemberList();

		ResultMessage message = new ResultMessage();
		message.put("userDataList", userDataList);
		message.put("departmentList", departmentList);
		message.put("departmentMemberList", departmentMemberList);
		return message;
	}

	@MethodMapping(value = "1.1.0005")
	public ResultMessage getUserHeadList() {
		List<UserHead> headList = departmentSerivce.getAllUserHeadList();
		ResultMessage message = new ResultMessage();
		message.put("headList", headList);
		return message;
	}

	@MethodMapping(value = "1.1.0006")
	public ResultMessage getDepartmentMemberIdList(@Define("departmentId") String departmentId) {
		List<String> userIdList = departmentMemberManager.getDepartmentMemberIdList(departmentId);
		ResultMessage message = new ResultMessage();
		message.put("userIdList", userIdList);
		return message;
	}

	@MethodMapping(value = "1.1.0007")
	public ResultMessage getDepartment(SocketSession socketSession, @Define("departmentId") String departmentId) {
		Department data = departmentSerivce.getDepartment(departmentId);
		ResultMessage message = new ResultMessage();
		message.put("department", data);
		return message;
	}
}
